//
//  CCQComposeView.swift
//  NEWweibo
//
//  Created by 神威 on 16/9/27.
//  Copyright © 2016年 ccq. All rights reserved.
//

import UIKit

class CCQComposeView: UIView {

    //  MARK: --    懒加载控件
    private lazy var sloganImageView: UIImageView = UIImageView(image: UIImage(named: "compose_slogan"))
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.size = CGSize(width: ScreenWidth, height: ScreenHeight)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        backgroundColor = RandomColor()
        //  获取模糊效果图片
        let image = UIImage.screenShot().applyLightEffect()
        let bgImageView = UIImageView(image: image)
        
        let pnf = 2;
        
        addSubview(bgImageView)
        
        addSubview(sloganImageView)
        
        sloganImageView.snp_makeConstraints { (make) in
            make.top.equalTo(self).offset(100)
            make.centerX.equalTo(self)
        }
        
        
        
        addChildButton()
        
    }
    
    //  添加子按钮
    private func addChildButton() {
        //  按钮的宽度
        let buttonWidth: CGFloat = 80
        //  按钮的高度
        let buttonHeight: CGFloat = 110
        //  按钮的间距
        let buttonMargin: CGFloat = (width - 3 * buttonWidth) / 4
        
        for i in 0..<6 {
            //  列的索引
            let colIndex = i % 3
            //  行的索引
            let rowIndex = i / 3
            
            
            let button = CCQComposeButton()
            button.x = CGFloat(colIndex) * buttonWidth + CGFloat(colIndex + 1) * buttonMargin
            button.y = CGFloat(rowIndex) * buttonHeight + CGFloat(rowIndex) * buttonMargin
            
            button.size = CGSize(width: buttonWidth, height: buttonHeight)
            button.setImage(UIImage(named: "tabbar_compose_idea"), for: .normal)
            button.setTitle("文字", for: .normal)
            
            addSubview(button)
        }
        
    }
    
    
    
    
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        removeFromSuperview()
    }
}
